package pl.enigmatic.util;

import java.awt.Color;

import pl.enigmatic.math.MathUtil;


public class Colors {

	private Colors() {}

	public static final int RGB255 = 255;

	/**
	 * Clamps the given color component value to proper [0, 255] range.
	 * @param val the component value
	 * @return value in the range [0, 255]
	 */
	public static int clampRGB255(final int val) {
		return pl.enigmatic.math.MathUtil.clamp(0, RGB255, val);
	}

	/**
	 * Wraps the given color component value to proper [0, 255] range.
	 * @param val the component value
	 * @return value in the range [0, 255]
	 */
	public static int wrapRGB255(final int val) {
		return MathUtil.wrap(0, RGB255, val);
	}

	public static Color reverse(final Color color, final int alpha) {
		return new Color(RGB255 - color.getRed(), RGB255 - color.getGreen(), RGB255 - color.getBlue(), clampRGB255(alpha));
	}

	public static Color reverse(final Color color, final boolean alsoAlpha) {
		return reverse(color, alsoAlpha ? RGB255 - color.getAlpha() : color.getAlpha());
	}

	public static Color reverse(final Color color) {
		return reverse(color, false);
	}
}
